{% for i in zookeeper_hosts %}
{%- if i.port is not defined and (i.host|d(i) == ansible_default_ipv4.address or i.host|d(i) == ansible_nodename) -%}
{%- if i.id is not defined -%}{{ loop.index }}{%- else -%}{{ i.id }}{%- endif -%}
{%- elif (i.host|d(i) == ansible_default_ipv4.address or i.host|d(i) == ansible_nodename) and i.port|d() == zookeeper_port -%} 
{%- if i.id is not defined -%}{{ loop.index }}{%- else -%}{{ i.id }}{%- endif -%}
{%- elif i.host|d(i) == '127.0.0.1' and i.port|d() == zookeeper_port -%}
{%- if i.id is not defined -%}{{ loop.index }}{%- else -%}{{ i.id }}{%- endif -%}
{%- endif -%}
{% endfor %}
